package cn.audit.controller.log;

import cn.audit.bean.dto.UserCorrelation;
import cn.audit.service.log.OperationLogService;
import cn.audit.utils.PagerUtil;
import cn.audit.utils.Paging;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author: 李忆枫
 * @Date: 2019/5/22 14:13
 */
@Controller
@RequestMapping("/log")
public class LogController {

    @Resource
    private OperationLogService logService;

    @RequestMapping("/OperationLog")
    public String OperationLog(Model model,
                               @RequestParam(value = "page", required = false) Integer page,
                               @RequestParam(value = "name", required = false) String name,
                               @RequestParam(value = "auditname", required = false) String auditname,
                               @RequestParam(value = "module", required = false) String module,
                               @RequestParam(value = "type", required = false) String content) throws ParseException {

        int page1 = 1;
        if (page != null) {
            page1 = page;
        }
        Sort sort = new Sort(Sort.Direction.DESC, "id");
        Pageable pages = PageRequest.of(page1 - 1, 10, sort);

        Page<UserCorrelation> articleDatas = logService.findLogAll(name, auditname, module, content, pages);
        model.addAttribute("pageCount", articleDatas.getTotalPages());
        List<UserCorrelation> logAll = articleDatas.getContent();
        model.addAttribute("logAll", logAll);
        //当前页数
        model.addAttribute("pager", page1);

        return "log/OperationLog";
    }

}
